﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class FormRoundBeamUseHand : System.Windows.Forms.Form
	{
		public FormRoundBeamUseHand(double angle)
		{
			this.angle = angle;
			this.InitializeComponent();
		}

		private void FormRoundBeamUseHand_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			base.CenterToScreen();
			if (this.angle == Math.PI*.5)
			{
				this.SJrB90.Checked = true;
				this.PYrb90.Checked = true;
				this.PYTBAngle.Enabled = false;
				this.SJtextboxAngle.Enabled = false;
			}
			else if (this.angle == 0.52359877559829882)
			{
				this.SJrB30.Checked = true;
				this.PYrb30.Checked = true;
				this.PYTBAngle.Enabled = false;
				this.SJtextboxAngle.Enabled = false;
			}
			string[] array = this.userSetting.GetpianyishengjiangText();
			this.SJtbDistance.Text = array[0];
			this.SJtextboxAngle.Text = array[1];
			if (array[2] == "两侧")
			{
				this.SJrBliangce.Checked = true;
			}
			else
			{
				this.SJrBdance.Checked = true;
			}
			this.PYtbDistance.Text = array[3];
			this.PYTBAngle.Text = array[4];
			if (array[5] == "两侧")
			{
				this.PYrbshuangce.Checked = true;
			}
			else
			{
				this.PYrbdance.Checked = true;
			}
			if (array[6] == "升降")
			{
				this.tabControl1.SelectedIndex = 0;
				base.AcceptButton = this.buttonSJOK;
				base.CancelButton = this.buttonSJESC;
				return;
			}
			this.tabControl1.SelectedIndex = 1;
			base.AcceptButton = this.buttonPYOK;
			base.CancelButton = this.buttonPYESC;
		}

		private Image getImage(string me)
		{
			return Image.FromFile(Path.Combine(Product.ResLocation, me + ".png"));
		}

		private void radiomodelSJ()
		{
			if (this.SJrBdance.Checked)
			{
				this.model = "单侧";
				this.SJPicture.Image = this.getImage("单侧升降");
				return;
			}
			if (this.SJrBliangce.Checked)
			{
				this.model = "两侧";
				this.SJPicture.Image = this.getImage("两侧升降");
			}
		}

		private void radiomodelPY()
		{
			if (this.PYrbdance.Checked)
			{
				this.model = "单侧";
				this.PYPicture.Image = this.getImage("单侧偏移");
				return;
			}
			if (this.PYrbshuangce.Checked)
			{
				this.model = "两侧";
				this.PYPicture.Image = this.getImage("两侧偏移");
			}
		}

		private void radionAngleSJ()
		{
			if (this.SJrB15.Checked)
			{
				this.angle = 0.26179938779914941;
				return;
			}
			if (this.SJrB30.Checked)
			{
				this.angle = 0.52359877559829882;
				return;
			}
			if (this.SJrB45.Checked)
			{
				this.angle = 0.78539816339744828;
				return;
			}
			if (this.SJrB60.Checked)
			{
				this.angle = 1.0471975511965976;
				return;
			}
			if (this.SJrB90.Checked)
			{
				this.angle = Math.PI*.5;
				return;
			}
			if (this.SJrBQT.Checked)
			{
				this.SJtextboxAngle.Enabled = true;
				if (this.SJtextboxAngle.Text != "")
				{
					this.angle = 0.017453292519943295 * double.Parse(this.SJtextboxAngle.Text.ToString());
					return;
				}
				YJKMessageBox.Show("请确保输入角度不为空！");
			}
		}

		private void radionAnglePY()
		{
			if (this.PYrb15.Checked)
			{
				this.angle = 0.26179938779914941;
				return;
			}
			if (this.PYrb30.Checked)
			{
				this.angle = 0.52359877559829882;
				return;
			}
			if (this.PYrb45.Checked)
			{
				this.angle = 0.78539816339744828;
				return;
			}
			if (this.PYrb60.Checked)
			{
				this.angle = 1.0471975511965976;
				return;
			}
			if (this.PYrb90.Checked)
			{
				this.angle = Math.PI*.5;
				return;
			}
			if (this.PYrbqita.Checked)
			{
				if (this.PYtbDistance.Text != "")
				{
					this.angle = 0.017453292519943295 * double.Parse(this.PYTBAngle.Text.ToString());
					return;
				}
				YJKMessageBox.Show("请确保输入角度不为空！");
			}
		}

		private void writeUserInfo()
		{
			string[] array = new string[7];
			array[0] = this.SJtbDistance.Text;
			array[1] = this.SJtextboxAngle.Text;
			if (this.SJrBdance.Checked)
			{
				array[2] = "单侧";
			}
			else
			{
				array[2] = "两侧";
			}
			array[3] = this.PYtbDistance.Text;
			array[4] = this.PYTBAngle.Text;
			if (this.PYrbdance.Checked)
			{
				array[5] = "单侧";
			}
			else
			{
				array[5] = "两侧";
			}
			if (this.tabControl1.SelectedIndex == 0)
			{
				array[6] = "升降";
			}
			else
			{
				array[6] = "偏移";
			}
			this.userSetting.WritepianyishengjiangText(array);
		}

		private void buttonPYOK_Click(object sender, EventArgs e)
		{
			if (!Regex.IsMatch(this.PYtbDistance.Text, "^[+-]?[0-9]+\\d*[.]?\\d*$"))
			{
				MessageBox.Show("偏移距离必须为有效数字", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.PYtbDistance.Focus();
				return;
			}
			if (!Regex.IsMatch(this.PYTBAngle.Text, "^[+-]?[0-9]+\\d*[.]?\\d*$"))
			{
				MessageBox.Show("偏移角度必须为有效数字", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.PYTBAngle.Focus();
				return;
			}
			if (this.tabControl1.SelectedIndex == 1)
			{
				if (this.PYrbqita.Checked && Convert.ToDouble(this.PYTBAngle.Text.Trim()) < 0.1)
				{
					MessageBox.Show("偏移角度过小", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					return;
				}
				if (this.PYtbDistance.Text != "")
				{
					this.radiomodelPY();
					this.SJORPY = "偏移";
					this.radionAnglePY();
					this.distance = double.Parse(this.PYtbDistance.Text) / 304.8;
					this.writeUserInfo();
					base.DialogResult = DialogResult.OK;
					return;
				}
				YJKMessageBox.Show("请确保偏移距离输入不为空！");
			}
		}

		private void buttonSJOK_Click(object sender, EventArgs e)
		{
			if (!Regex.IsMatch(this.SJtbDistance.Text, "^[+-]?[0-9]+\\d*[.]?\\d*$"))
			{
				MessageBox.Show("升降高度必须为有效数字", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.SJtbDistance.Focus();
				return;
			}
			if (!Regex.IsMatch(this.SJtextboxAngle.Text, "^[+-]?[0-9]+\\d*[.]?\\d*$"))
			{
				MessageBox.Show("升降角度必须为有效数字", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.SJtextboxAngle.Focus();
				return;
			}
			if (this.tabControl1.SelectedIndex == 0)
			{
				if (this.SJrBQT.Checked && Convert.ToDouble(this.SJtextboxAngle.Text.Trim()) < 0.1)
				{
					MessageBox.Show("偏移角度过小", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					return;
				}
				if (this.SJtbDistance.Text != "")
				{
					this.radiomodelSJ();
					this.SJORPY = "升降";
					this.radionAngleSJ();
					this.distance = double.Parse(this.SJtbDistance.Text) / 304.8;
					this.writeUserInfo();
					base.DialogResult = DialogResult.OK;
					return;
				}
				YJKMessageBox.Show("请确保升降距离输入不为空！");
			}
		}

		private void buttonPYESC_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void buttonSJESC_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void PYrbqita_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnablePY();
		}

		private void setEnable()
		{
			if (this.SJrB15.Checked)
			{
				this.SJtextboxAngle.Enabled = false;
				return;
			}
			if (this.SJrB30.Checked)
			{
				this.SJtextboxAngle.Enabled = false;
				return;
			}
			if (this.SJrB45.Checked)
			{
				this.SJtextboxAngle.Enabled = false;
				return;
			}
			if (this.SJrB60.Checked)
			{
				this.SJtextboxAngle.Enabled = false;
				return;
			}
			if (this.SJrB90.Checked)
			{
				this.SJtextboxAngle.Enabled = false;
				return;
			}
			if (this.SJrBQT.Checked)
			{
				this.SJtextboxAngle.Enabled = true;
			}
		}

		private void setEnablePY()
		{
			if (this.PYrb15.Checked)
			{
				this.PYTBAngle.Enabled = false;
				return;
			}
			if (this.PYrb30.Checked)
			{
				this.PYTBAngle.Enabled = false;
				return;
			}
			if (this.PYrb45.Checked)
			{
				this.PYTBAngle.Enabled = false;
				return;
			}
			if (this.PYrb60.Checked)
			{
				this.PYTBAngle.Enabled = false;
				return;
			}
			if (this.PYrb90.Checked)
			{
				this.PYTBAngle.Enabled = false;
				return;
			}
			if (this.PYrbqita.Checked)
			{
				this.PYTBAngle.Enabled = true;
			}
		}

		private void SJrBQT_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnable();
		}

		private void SJrB15_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnable();
		}

		private void SJrB30_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnable();
		}

		private void SJrB45_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnable();
		}

		private void SJrB60_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnable();
		}

		private void SJrB90_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnable();
		}

		private void PYrb15_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnablePY();
		}

		private void PYrb30_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnablePY();
		}

		private void PYrb45_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnablePY();
		}

		private void PYrb60_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnablePY();
		}

		private void PYrb90_CheckedChanged(object sender, EventArgs e)
		{
			this.setEnablePY();
		}

		private void SJtextboxAngle_TextChanged(object sender, EventArgs e)
		{
		}

		private void SJtextboxAngle_Validated(object sender, EventArgs e)
		{
			if (!this.regex3.IsMatch(this.SJtextboxAngle.Text))
			{
				YJKMessageBox.Show("角度请输入数字,且必须为正！");
				this.SJtextboxAngle.Focus();
				this.SJtextboxAngle.SelectAll();
				return;
			}
			if (this.regex.IsMatch(this.SJtextboxAngle.Text) && Convert.ToDouble(this.SJtextboxAngle.Text.Trim()) > 90.0)
			{
				YJKMessageBox.Show("角度不能大于90度！");
				this.SJtextboxAngle.Focus();
				this.SJtextboxAngle.SelectAll();
				return;
			}
		}

		private void PYTBAngle_Validated(object sender, EventArgs e)
		{
			if (!this.regex3.IsMatch(this.PYTBAngle.Text))
			{
				YJKMessageBox.Show("角度请输入数字,且必须为正！");
				this.PYTBAngle.Focus();
				this.PYTBAngle.SelectAll();
				return;
			}
			if (this.regex.IsMatch(this.PYTBAngle.Text) && Convert.ToDouble(this.PYTBAngle.Text.Trim()) > 90.0)
			{
				YJKMessageBox.Show("角度不能大于90度！");
				this.PYTBAngle.Focus();
				this.PYTBAngle.SelectAll();
				return;
			}
		}

		private void PYrbdance_CheckedChanged(object sender, EventArgs e)
		{
			this.radiomodelPY();
		}

		private void PYrbshuangce_CheckedChanged(object sender, EventArgs e)
		{
			this.radiomodelPY();
		}

		private void SJrBdance_CheckedChanged(object sender, EventArgs e)
		{
			this.radiomodelSJ();
		}

		private void SJrBliangce_CheckedChanged(object sender, EventArgs e)
		{
			this.radiomodelSJ();
		}

		private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.tabControl1.SelectedIndex == 0)
			{
				base.AcceptButton = this.buttonSJOK;
				base.CancelButton = this.buttonSJESC;
				return;
			}
			base.AcceptButton = this.buttonPYOK;
			base.CancelButton = this.buttonPYESC;
		}

		public double distance;

		public double angle = 1.0471975511965976;

		public string model = "双侧";

		public string SJORPY = "升降";

		private HVACUserSetting userSetting = new HVACUserSetting();

		private Regex regex = new Regex("^[0-9]+(.[0-9]{1,3})?$");

		private Regex regex3 = new Regex("^[0-9]+(.[0-9]{1,3})?$");
	}
}
